package winOrDie.graphicsInterface.GameRoom;

import java.util.ArrayList;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;

import winOrDie.Net.Client.WoD_Peer;

public class Composite_Player_List extends Composite {

	private ScrolledComposite scrolledComposite = null;
	private Composite composite_Table = null;
	
	private ArrayList<WoD_Peer> woDClientPeers = new ArrayList<WoD_Peer>();
	
	
	private void test()
	{
		WoD_Peer clientPeer = new WoD_Peer();
		clientPeer.setUserName("Client 1");
		woDClientPeers.add(clientPeer);
		WoD_Peer clientPeer2 = new WoD_Peer();
		clientPeer2.setUserName("Client 2");
		woDClientPeers.add(clientPeer2);
		WoD_Peer clientPeer3 = new WoD_Peer();
		clientPeer3.setUserName("Client 3");
		woDClientPeers.add(clientPeer3);
		WoD_Peer clientPeer4 = new WoD_Peer();
		clientPeer4.setUserName("Client 4");
		woDClientPeers.add(clientPeer4);
		
		paint_Table();
		redraw();
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		woDClientPeers.remove(2);
		
		paint_Table();
		
	}

	public Composite_Player_List(Composite parent, int style) {
		super(parent, style);
		initialize();
		//test();
	}

	private void initialize() {
		createScrolledComposite();
		setSize(new Point(300, 200));
		setLayout(new FillLayout());
		
		
	}

	/**
	 * This method initializes scrolledComposite	
	 *
	 */
	private void createScrolledComposite() {
		scrolledComposite = new ScrolledComposite(this, SWT.NONE);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		createComposite();
		scrolledComposite.setContent(composite_Table);
		
	}

	/**
	 * This method initializes composite	
	 *
	 */
	private void createComposite() {
		composite_Table = new Composite(scrolledComposite, SWT.V_SCROLL | SWT.BORDER);
		composite_Table.setLayout(new GridLayout());
	}

	
	public void paint_Table()
	{
		for (Control composite : composite_Table.getChildren()) {
			composite.dispose();
		}
		
		for (WoD_Peer peer : woDClientPeers) {
			Composite_Player_List_Item compositePlayerListItem = 
				new Composite_Player_List_Item(composite_Table, SWT.NONE);
			compositePlayerListItem.setClientPeer(peer);
			
		}
	}
	
}
